package com.utils;

import java.io.*;
import java.util.ArrayList;

public class FileUtilsForLinkList {



    /**
     * 读数据文件
     * @param path
     */
    public MyLinkList readFile(String path) throws IOException {
        //步骤：
        //1.创建文件对象
        File file = new File(path);
        //2.实例化流对象  字节流
        InputStream inputStream = new FileInputStream(file);
        //3. 处理流
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"GBK"));

        //读取
        Map map = null;
        MyLinkList maps = new MyLinkList();


        while (true){
            String str = bufferedReader.readLine();
            if (str == null) break;
            //  System.out.println(str);

            map = change(str);
            maps.addLast(map);
        }
        return maps;

        //4. 转换对象
        //5. 存入集合

    }


    //#linkID=4435;roadnameflag=1;branch=0;dispclass=8;roadname=?????·
    public Map change(String content){
        String [] items = content.split(";");
        Map map = new Map();
        map.setLinkID(Integer.parseInt(items[0].split("=")[1].trim()));
        map.setRoadnameflag(Integer.parseInt(items[1].split("=")[1].trim()));
        map.setBranch(Integer.parseInt(items[2].split("=")[1].trim()));
        map.setDispclass(Integer.parseInt(items[3].split("=")[1].trim()));
        if (map.getRoadnameflag() == 1){
            map.setRoadname(items[4].split("=")[1].trim());
        }

        return map;
    }


}
